package com.itheima.web;

import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.pojo.Result;
import com.itheima.pojo.ResultPageBean;
import com.itheima.pojo.Sku;
import com.itheima.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("item")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @PostMapping("add")
    public void addGoods(@RequestBody Sku sku){
        goodsService.add(sku);

    }
    @PostMapping("update")
    public void updateByID(@RequestBody Sku sku){
        goodsService.updateByID(sku);

    }
    @GetMapping("delete/{id}")
    public void deleteById(@PathVariable("id")String id){
        goodsService.deleteById(id);

    }
    @GetMapping("getSkuById/{id}")
    public Result selectById(@PathVariable("id")String id){
        Sku sku =goodsService.selectById(id);
        return Result.ok(sku);
    }
    @GetMapping("findByPage/{pageSize}/{currentPage}")
    public Result findByPage(@PathVariable("pageSize")int pageSize,@PathVariable("currentPage") int currentPage){

        ResultPageBean skus = goodsService.findByPage(pageSize,currentPage);
        return Result.ok(skus);

    }
    @GetMapping("getTotal")
    public Integer getTotal(){
        return goodsService.getTotal();
    }


}
